import {
  FdxPlugin,
  IESupportPlugin,
  DvaPlugin,
  LocalePlugin,
} from '@fishx/plugins';

import postcssConfig from './postcss.config';

const swaggerProxy = `SWAGGERPROXY`;
const zmpTarget = 'https://zmp.iwhalecloud.com/meetingApply';
const portalReactTarget = 'http://portal-react-dxp.uportal.svc.tb.zsmart.com/portal';
const portalDxpTarget = 'http://ngportal-develop-dxp-dev2.uportal.svc.tb.zsmart.com:8080/portal';

const config = {
  title: 'fishx',
  plugins: [
    new FdxPlugin({ loadOnDemand: false }),
    new IESupportPlugin(),
    new DvaPlugin(),
    new LocalePlugin(),
  ],
  router: {
    history: 'hash',
  },
  staticProxyPaths: [
    '/portal',
  ],
  proxy: {
    ...JSON.parse(swaggerProxy),
    '/portal/api': {
      target: portalDxpTarget,
      changeOrigin: true,
      pathRewrite: { '^/portal/api': '' },
    },
    // Portal的静态资源，指向远程
    '/portal': {
      target: portalReactTarget,
      changeOrigin: true,
      pathRewrite: { '^/portal': '' },
    },
    '/meetingApply': {
      target: zmpTarget,
      changeOrigin: true,
      pathRewrite: { '^/meetingApply': '' },
    },
    '/PROJECTNAME/api': {
      target: 'http://localhost:8888',
      changeOrigin: true,
      pathRewrite: { '^/PROJECTNAME/api': '/PROJECTNAME' },
    }
  },
  publicPath: '/PROJECTNAME',
  externals: {
    'react': 'window.React',
    'react-dom': 'window.ReactDOM',
    '../moment': 'window.moment',
    'moment': 'window.moment',
    // 'react-redux': 'window.ReactRedux',
    '@whalecloud/fdx': 'window.fdx',
  },
  analyze: {
    analyzerPort: 7788,
  },
  extraPostCSSPlugins: postcssConfig.plugins
};

export default config;
